package com.tuniu.agents.impl.trip.chain;

import com.tuniu.agents.impl.trip.OnlineSearcher;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OnlineSearcherHandler extends TripChainHandler {
    private final OnlineSearcher tripSearchAgent;

    public OnlineSearcherHandler(OnlineSearcher tripSearchAgent) {
        super("OnlineSearcherHandler");
        this.tripSearchAgent = tripSearchAgent;
    }

    @Override
    public String handle(String conversationId, String message) {
        try {
            logStart();
            String result = tripSearchAgent.call(conversationId, message);
            if (result == null || result.isEmpty()) {
                return "Unable to search trip information, please try again.";
            }
            logEnd();
            return handleNext(conversationId, result);
        } catch (Exception e) {
            logError(e);
            return "Failed to search trip information: " + e.getMessage();
        }
    }
} 